<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends CI_Controller {
	
	private $tab = 'global';
	function __construct(){
		parent::__construct();
		if(!isset($_SESSION)){
		    session_start();
		}
		$admin = $this->session->userdata('admin_user');
		if(!$admin || !isset($admin['user_id'])){
			header('Location: /ychadmin/login');
			exit;
		}
	}
	
	function index(){
		$data['tab'] = $this->tab;
		$data['sub'] = 'welcome';
		$this->load->model('Borrow_model');
		$this->load->model('User_model');
		$this->load->model('Attestation_model');
		$this->load->model('Accountcash_model');
		//等待初审的标
		$fstatus = 'fstaus';
		$data['fstatusNum'] = $this->Borrow_model->first_total($fstatus);
		//等待复审的标
		$qtype = 'qtype';
		$data['qtypeNum'] = $this->Borrow_model->first_total($qtype);
		//等待VIP认证的会员
		$vip_status = 2;
		$data['vipNum'] = $this->User_model->vip_no_num($vip_status);
		//等待实名认证的会员
		$real_status = 2;
		$data['realNum'] = $this->User_model->real_status_count($real_status);
		//认证资料等待审核记录
		$attestation_status = 0;
		$data['attestationNum'] = $this->Attestation_model->attestation_count($attestation_status);
		//等待审核提现记录
		$accountcash_status = 0;
		$data['accountcashNum'] = $this->Accountcash_model->accountcash_count_nums($accountcash_status);
		$this->load->view('/ychadmin/welcome', $data);
	}
	
	function passwd(){
		$this->load->model('systemadmin_model');
		
		$admin = $this->session->userdata('admin_user');
		$id = $admin['id'];
		$data = $this->systemadmin_model->getone_systemadmin_user("id='$id'");
		
		$data['tab'] = $this->tab;
		$data['sub'] = 'passwd';
		
		$this->load->view('/ychadmin/welcome_passwd',$data);
	}
	
	function passwd_edit(){
		$passwd = $this->input->post('password');
		$adminname = $this->input->post('adminname');
		$data = array(
			'password'   => md5(md5($passwd)),
			'remark'     => $this->input->post('remark')
		);
		
		$data['update_time'] = time();
		$data['update_ip']   = $_SERVER['REMOTE_ADDR'];
		
		$this->load->model('systemadmin_model');
  		$systemset_id = $this->systemadmin_model->update($this->input->post('id'),$data);
  		$this->load->model('log_model');
  		$this->log_model->add_log($adminname.'[修改管理员密码][全局管理]');
  		header("location:/ychadmin/welcome/index/");
   		exit;
	}
}